//
// Created by madison on 2022/1/10.
//

#include <iostream>

using namespace std;

class Line {
public:
    void setLength(double len);

    double getLength(void);

    Line();

    ~Line();  // 这是析构函数声明

    Line(double len);  // 这是构造函数
private:
    double length;
};

// 类的构造函数
Line::Line(void) {
    cout << "Object is being created" << endl;
}

// 使用初始化列表来初始化字段
//Line::Line(double len) : length(len) {
//    cout << "Object is being created, length = " << len << endl;
//}

// 上面的语法等同于如下语法：
// 带参数的构造函数
Line::Line(double len) {
    cout << "Object is being created, length = " << len << endl;
    length = len;
}

Line::~Line(void) {
    cout << "Object is being deleted" << endl;
}

void Line::setLength(double len) {
    length = len;
}

double Line::getLength(void) {
    return length;
}

// 程序的主函数
int main() {
    Line line;

    // 设置长度
    line.setLength(6.0);
    cout << "Length of line : " << line.getLength() << endl;


    Line line1(10.0);

    // 获取默认设置的长度
    cout << "Length of line : " << line1.getLength() << endl;
    // 再次设置长度
    line1.setLength(6.0);
    cout << "Length of line : " << line1.getLength() << endl;

    return 0;
}